package com.xxx.video.channel.adapters;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.xxx.video.R;
import com.xxx.video.channel.beans.ChanelHomeListBean;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.adapters.BaseViewHolder;
import com.xxx.video.commen.utils.ResourcesUtils;
import com.xxx.video.commen.utils.StringUtils;

import butterknife.BindView;

public class HotChannelListAdapter extends BaseRecycleViewAdapter<ChanelHomeListBean.HotListBean, HotChannelListAdapter.MyHolder> {

    public HotChannelListAdapter(@NonNull Context context) {
        super(context);
    }

    @Override
    public MyHolder onCreateDefaultViewHolder(View view, int viewType) {
        return new MyHolder(view);
    }

    @Override
    public int getItemLayout(int viewType) {
        return R.layout.item_hot_channel_list;
    }


    class MyHolder extends BaseViewHolder {

        @BindView(R.id.iv_hot_channel_list_cover)
        ImageView ivHotChannelListCover;
        @BindView(R.id.tv_hot_channel_list_name)
        TextView tvHotChannelListName;

        public MyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData2View(int position) {
            ChanelHomeListBean.HotListBean hotListBean = getItem(position);
            /*
             * init avatar
             */
            if (TextUtils.isEmpty(hotListBean.fPicurl)) {
                Glide.with(context).load(R.drawable.bg_place_holder_one_one)
                        .apply(new RequestOptions().circleCrop()).into(ivHotChannelListCover);
            } else {
                Glide.with(context).load(ResourcesUtils.getInstance().getImagePath(hotListBean.fPicurl)).apply(new RequestOptions().circleCrop()
                        .placeholder(R.drawable.bg_place_holder_one_one)
                        .error(R.drawable.bg_place_holder_one_one)
                ).into(ivHotChannelListCover);
            }
            /*
             * init name
             */
            tvHotChannelListName.setText(StringUtils.getInstance().getNotEmptyMsg(hotListBean.fName));
        }
    }
}
